package com.tanhua.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tanhua.domain.Log;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface LogMapper extends BaseMapper<Log> {

    //统计当天注册用户
    @Select("select COUNT(distinct user_id) from tb_log where type=#{type} and log_time=#{today}")
    Integer findNumRegistered(@Param("today") String today, @Param("type") String s);


    //统计当天登录用户
    @Select("select COUNT(distinct user_id) from tb_log where type=#{type} and log_time=#{today}")
    Integer findNumLogin(@Param("today") String today, @Param("type") String s);

    //统计活跃用户
    @Select("select COUNT(distinct user_id) from tb_log where log_time=#{today}")
    Integer findNumActive(String today);


    //统计留存数
    @Select("select COUNT(distinct user_id) from tb_log where log_time=#{today}\n" +
            "and user_id in\n" +
            "(\n" +
            " select distinct user_id from tb_log where type='0102' and log_time=#{yesterday}\n" +
            ")")
    Integer findNumRetention1d(@Param("yesterday") String yesterday,@Param("today") String today);



    //统计今日注册或登录用户数量  String s = 0102  type
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE log_time=#{today} AND TYPE =#{type}")
    Integer queryNumRegisteredOrLogin(@Param("today") String todayStr, @Param("type") String s);


    //查询今日活跃用户数量
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE log_time=#{todayStr}")
    Integer queryNumActive(@Param("todayStr") String todayStr);
}
